<template>
    <div class="edu-page-warp">
        <el-card shadow="never">
            <div class="edu-page-title">学生信息</div>
            <hr style="margin:10px 0" />
            <el-form label-position="right" label-width="150px" label-suffix="：" id="stu-info">
                <el-row>
                    <el-col :span="colSpan">
                        <el-form-item :label="$t('label.stuCode')">{{currentStudent.studentId}}</el-form-item>
                    </el-col>
                    <el-col :span="colSpan">
                        <el-form-item :label="$t('label.stuName')">{{currentStudent.name}}</el-form-item>
                    </el-col>
                    <el-col :span="colSpan">
                        <el-form-item :label="$t('label.college')">{{currentStudent.facultyI18n}}</el-form-item>
                    </el-col>
                    <el-col :span="colSpan">
                        <el-form-item :label="$t('label.major')">{{currentStudent.professionI18n}}</el-form-item>
                    </el-col>

                    <el-col :span="colSpan">
                        <el-form-item :label="$t('label.grade')">{{currentStudent.grade}}</el-form-item>
                    </el-col>
                    <el-col :span="colSpan">
                        <el-form-item label="导师">
                            <span
                                v-if="currentStudent.teacherId"
                            >{{currentStudent.teacherName}}({{currentStudent.teacherId}})</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="colSpan">
                        <el-form-item
                            :label="$t('label.trainingLevel')"
                        >{{currentStudent.trainingLevelI18n}}</el-form-item>
                    </el-col>
                    <el-col :span="colSpan">
                        <el-form-item label="申请类型">{{currentStudent.permitTypeI18n}}</el-form-item>
                    </el-col>

                    <el-col :span="colSpan">
                        <el-form-item
                            :label="$t('dic.degreeType')"
                        >{{currentStudent.degreeTypeI18n}}</el-form-item>
                    </el-col>
                    <el-col :span="colSpan">
                        <el-form-item
                            :label="$t('label.formLearning')"
                        >{{currentStudent.formLearningI18n}}</el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-card>
        <apply-form
            v-if="showForm"
            ref="applyForm"
            :options="options"
            @close="handleReturn"
            @success="handleSave"
            :students="[currentStudent]"
            :showSaveBtn="true"
            :mas-profession="currentStudent.profession"
            :teacherId="currentStudent.teacherId"
        />
    </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import {
    getStudentInfo,
    getStuTeas,
    getGraduateDegreeByColleges
} from "common/src/api/culture/change";

import ApplyForm from "./ApplyForm";
import mixin from 'common/src/mixins/index';
export default {
    name: "MyDoctorToMaster",
    mixins: [mixin],
    components: {
        ApplyForm
    },
    data: function() {
        return {
            showForm: false,
            currentStudent: {
                studentId: null,
                name: null,
                facultyI18n: null,
                professionI18n: null,
                grade: null,
                teacherName: null,
                trainingLevelI18n: null,
                trainingCategoryI18n: null,
                degreeTypeI18n: null,
                formLearningI18n: null
            },
            options: {
                enrolSeason: [],
                applyReason: [],
                masProfessions: [],
                masTeachers: []
            }
        };
    },
    mounted() {
        let user = this.global.mockUser || this.global.user;

        this.currentStudent.name = user.name;
        this.currentStudent.grade = user.grade;
        this.currentStudent.studentId = user.uid;
        getStudentInfo(user.uid).then(res => {
            if (res.code == 200) {
                this.showForm = true;
                this.currentStudent = res.data[0];
                this.init();
            }
        });
    },
    computed: {
        colSpan() {
            if (this.currentStudent == null) {
                return 6;
            }
            if (
                this.currentStudent.facultyI18n &&
                this.currentStudent.facultyI18n.length >= 8
            ) {
                return 8;
            }
            if (
                this.currentStudent.professionI18n &&
                this.currentStudent.professionI18n.length >= 8
            ) {
                return 8;
            }
            return 6;
        }
    },
    methods: {
        init() {
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["K_SQYY", "X_RXJJ"]
            };
            queryDic(data).then(res => {
                if (res.code === 200) {
                    this.fill("applyReason", res.data.K_SQYY);
                    this.fill("enrolSeason", res.data.X_RXJJ);
                }
            });
            getGraduateDegreeByColleges({}).then(res => {
                if (res.code == 200) {
                    let language = this.$store.getters.language || "cn";
                    this.options.masProfessions = res.data.map(row => {
                        return {
                            label:
                                (language == "cn" ? row.nameCN : row.nameEn) +
                                " (" +
                                row.code +
                                ")",
                            value: row.code
                        };
                    });
                }
            });
            getStuTeas().then(res => {
                if (res.code == 200) {
                    let teachers = [];
                    for (let key in res.data) {
                        this.options.masTeachers.push({
                            label: res.data[key] + "(" + key + ")",
                            value: key
                        });
                    }
                }
            });
        },
        fill(type, data) {
            for (const key in data) {
                this.options[type].push({
                    value: key,
                    label: data[key]
                });
            }
        },
        handleReturn() {
            this.$router.push("/DoctorToMasterManage");
            this.$store.commit("delete_tabs", "/MyDoctorToMaster");
        },
        handleSave() {
            this.$router.push("/DoctorToMasterManage");
            this.$store.commit("delete_tabs", "/MyDoctorToMaster");
        }
    }
};
</script>
<style lang="scss" scoped>
</style>